package com.zqll.gdx.starter.assets;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.utils.I18NBundle;
import com.badlogic.gdx.utils.viewport.ScreenViewport;

/**
 * StarterAssets 统一加载示例：展示皮肤 + i18n + 中文字体。
 */
public class StarterAssetsExample extends ApplicationAdapter {

    public static void main(String[] args) {
        new Lwjgl3Application(new StarterAssetsExample());
    }

    private Stage stage;
    private Skin skin;
    private I18NBundle i18n;

    @Override
    public void create() {
        stage = new Stage(new ScreenViewport());
        Gdx.input.setInputProcessor(stage);

        // 统一初始化与加载
        StarterAssets.init();
        StarterAssets.loadDefaults();

        skin = StarterAssets.getSkin();
        i18n = StarterAssets.getI18N();

        Table root = new Table();
        root.setFillParent(true);

        Label.LabelStyle ls = new Label.LabelStyle();
        ls.font = StarterAssets.font(20);
        ls.fontColor = Color.WHITE;

        Label title = new Label(i18n.get("app.title"), ls);
        Label hello = new Label(i18n.get("hello"), ls);

        TextButton.TextButtonStyle bs = new TextButton.TextButtonStyle();
        bs.font = StarterAssets.font(18);
        bs.fontColor = Color.WHITE;
        TextButton start = new TextButton(i18n.get("start"), bs);
        TextButton cancel = new TextButton(i18n.get("cancel"), bs);

        root.add(title).pad(12).row();
        root.add(hello).pad(8).row();
        root.add(start).pad(6).row();
        root.add(cancel).pad(6).row();

        stage.addActor(root);
    }

    @Override
    public void render() {
        Gdx.gl.glClearColor(0.15f, 0.15f, 0.18f, 1f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        stage.act();
        stage.draw();
    }

    @Override
    public void dispose() {
        stage.dispose();
        StarterAssets.dispose();
    }
}